package com.sren.boot.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @author: renshuai
 * @date: 2019/11/25 上午9:33
 * @Description: 系统属性条件判断
 */
public class OnSystemPropertyCondition implements Condition {
	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnSystemProperty.class.getName());
		String propertyName = String.valueOf(attributes.get("name"));
		String propertyValue = String.valueOf(attributes.get("value"));

		String javaPropertyValue = System.getProperty(propertyName);

		return propertyValue.equals(javaPropertyValue);
	}
}
